package generics.rawtype;

import java.util.ArrayList;
import java.util.Arrays;
@SuppressWarnings("unchecked")
public class Stack<E> {

    private E[] elements;
    private int size = 0;
    private  static  final int DEFAULT_INTI_CAPACITY = 16;

    public Stack(){
        elements = (E[]) new Object[DEFAULT_INTI_CAPACITY];

    }

    public void pushAll(Iterable<? extends E> src) {
        for (E e: src) {
            push(e);
        }
    }

    public void push(E o) {
        ensureCapacity();
        elements[size++] = o;
    }

    private void ensureCapacity(){
        if (elements.length == size) {
            elements = Arrays.copyOf(elements, 2 * size + 1);
        }
    }
    public static void main(String args[]) {
        Stack<Number> stacks = new Stack<>();
        Iterable<Integer> integers = new ArrayList<>();
        stacks.pushAll(integers);
    }
}
